from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base():
    def __init__(self):
        cap={
  "platformName": "Android",
  "appium:deviceName": "emulator-5554",
  "appium:automationName": "uiautomator2",
  "appium:appPackage": "com.xiachufang",
  "appium:appActivity": ".activity.home.HomeActivity",
  "appium:noReset": True
}
        self.devices=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.devices.implicitly_wait(20)

    def find_loc(self,loc):
        ele=self.devices.find_element(*loc)
        return ele

    # 滑动
    def huadong(self,a,b,c,d):
        self.devices.swipe(a,b,c,d,300)

    # 点击
    def dianji(self,a,b):
        self.devices.tap([(a,b)],300)

    def tuichu(self):
        self.devices.quit()

    def xianshi(self,loc):
        ele=WebDriverWait(self.devices,300).until(EC.element_to_be_clickable(loc))
        return ele
    def jieitu(self,a):
        self.devices.save_screenshot(a)
